<template>
  <Layout>
    <!-- Page Header -->
    <header class="masthead" 
      :style="{
        backgroundImage: `url(http://8.131.86.203:1337${$page.general.cover.url}`
      }"
    >
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="site-heading">
              <h1>{{$page.general.title}}</h1>
              <span class="subheading">{{$page.general.subtitle}}</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Main Content -->
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <div class="post-preview" v-for="article in $page.articles.edges" :key="article.node.id">
            <a href="post.html">
              <h2 class="post-title">{{article.node.title}}</h2>
              <!-- <h3 class="post-subtitle">Problems look mighty small from 150 miles up</h3> -->
            </a>
            <p class="post-meta">
              Posted by
              <a href="#">
                {{article.node.createdBy.firstname}}
                {{article.node.createdBy.lastname}}
              </a>
              {{article.node.published_at}}
            </p>
            <p>
              <span v-for="tag in article.node.tags" :key="tag.name">
                <g-link :to="'/tag/' + tag.id">{{tag.name}}</g-link>&nbsp;
              </span>
            </p>
            <hr />
          </div>
          <!-- Pager -->
          <!-- <div class="clearfix">
            <a class="btn btn-primary float-right" href="#">Older Posts &rarr;</a>
          </div>-->
          <Pager :info="$page.articles.pageInfo" />
        </div>
      </div>
    </div>
  </Layout>
</template>

<page-query>
query ($page: Int) {
  articles: allStrapiArticle (perPage: 2, page: $page) @paginate {
    pageInfo {
      totalPages
      currentPage
    }
    edges {
      node {
        id
        title
        published_at
        createdBy {
          id
          firstname
          lastname
        }
        tags {
          id
          name
        }
      }
    }
  }
  general: strapiGeneral (id: 1) {
    title
    subtitle
    cover {
      url
    }
  }
}
</page-query>

<script>
import { Pager } from "gridsome";

export default {
  components: {
    Pager
  },
  metaInfo: {
    title: "Hello, world!"
  },
  mounted() {
    console.log(this.$page);
  }
};
</script>

<style>
</style>
